import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common';
import { MenuService } from './menu.service';
import { CreateMenuDto } from './dto/create-menu.dto';
import { UpdateMenuDto } from './dto/update-menu.dto';
import { ApiTags, ApiOperation, ApiResponse } from '@nestjs/swagger';
import { BaseController } from 'src/common/BaseController';
import { Menu } from './entities/menu.entity';
import { QueryMenuDto } from './dto/query-menu.dto';
import { ResponsInterceptoreBase } from '../../../transform.interceptor';
import { UseInterceptors } from '@nestjs/common';

@ApiTags('菜单管理')
@Controller('menu')
@UseInterceptors(ResponsInterceptoreBase)
export class MenuController extends BaseController<Menu, MenuService> {
  constructor(private readonly menuService: MenuService) {
    super(menuService);
  }

  @Post("addMenu")
  @ApiOperation({ summary: '添加菜单' })
  async addMenu(@Body() createMenuDto: CreateMenuDto) {
    let result = await this.menuService.create(createMenuDto);
    console.log(result);
    if(result[0]) {
      return this.Success(result[1], "菜单添加成功");
    }else{
      return this.Fail(result[1], "菜单添加失败");
    }
  }

  @Post('updateMenu')
  @ApiOperation({ summary: '更新菜单' })
  async update( @Body() updateMenuDto: UpdateMenuDto) {
    let result = await this.menuService.update(updateMenuDto);
    if(result[0]) {
      return this.Success(result[1], "菜单更新成功");
    }else{
      return this.Fail(result[1], "菜单更新失败");
    }
  }

  @Post('DeleteMenu')
  async remove(@Body() IdArr: Array<string>) {
    let result = await this.menuService.remove(IdArr);
    if(result[0]) {
      return this.Success(result[1], "菜单删除成功");
    }else{
      return this.Fail(result[1], "菜单删除失败");
    }
  }

  @Post('GetMenuList')
  @ApiOperation({ summary: '获取菜单列表' })
  async GetMenuList(@Body() query: QueryMenuDto) {
    let menus = await this.menuService.GetMenuList(query);
    return this.Success(menus, "菜单列表获取成功");
  }
}
